package com.bionic.banking.dao.connection;

import com.bionic.banking.auth.manager.Config;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCConnectionFactory {

    private static String driverClassName;// = "com.mysql.jdbc.Driver";
    private static String connectionUrl;// = "jdbc:mysql://localhost:3306/bionicwebmoneydb";
    private static String dbUser;// = "root";
    private static String dbPwd;//= "";            
    private static JDBCConnectionFactory connectionFactory = null;

    public static JDBCConnectionFactory getInstance() throws SQLException {
        if (connectionFactory == null) {
            connectionFactory = new JDBCConnectionFactory();
        }
        return connectionFactory;
    }

    private JDBCConnectionFactory() throws SQLException {
        driverClassName = Config.getInstance().getProperty(Config.DRIVER);
        try {
            Class.forName(driverClassName);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            throw new SQLException("Deriver '" + driverClassName + "' not Found");
        }
    }

    public Connection getConnection() throws SQLException {
        connectionUrl = Config.getInstance().getProperty(Config.URL);
        dbUser = Config.getInstance().getProperty(Config.DBUser);
        dbPwd = Config.getInstance().getProperty(Config.DBPwd);
        return DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
    }
}